const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('month_medicine_lib', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED.ZEROFILL,
      allowNull: false,
      primaryKey: true
    },
    current_year_month: {
      type: DataTypes.DATEONLY,
      allowNull: false
    },
    medicine_lib_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'medicine_lib',
        key: 'id'
      }
    },
    prev_month_remain_amount: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    current_month_in_amount: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    prev_month_record_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false
    },
    unit_price: {
      type: DataTypes.DOUBLE,
      allowNull: false
    },
    out_lib_amount: {
      type: DataTypes.INTEGER,
      allowNull: false
    }
  }, {
    sequelize,
    tableName: 'month_medicine_lib',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "FK_month_medicine_lib",
        using: "BTREE",
        fields: [
          { name: "medicine_lib_id" },
        ]
      },
    ]
  });
};
